﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using dotNails.CodeGen.Models;

namespace dotNails.CodeGen.Models.dotNailsLinqToSqlGenerator {
	public class DataContextClass : CodeBlock {
		private DataBase DB { get; set; }
		public string XmlNamespace { get; set; }
		
		public DataContextClass(DataBase db) {
			DB = db;

			TemplateFileName = Path.Combine(TemplatePath, "DataContext.cst");
			XmlNamespace = DB.XmlNamespace;
		}
		
		public override void PopulateTemplate(BaseCodeTemplate template) {
			base.PopulateTemplate(template);

			DataContextTemplate dbTemplate = template as DataContextTemplate;

			if (dbTemplate != null) {
				// Populate properties on the base template
				dbTemplate.EntityBaseClass = "DotNailsDataContext";
				dbTemplate.Namespace = "";
				dbTemplate.EntityClass = DB.Class; 
				dbTemplate.DB = DB;
				dbTemplate.DbmlName = DB.Class.Replace("DataContext", "");
			}
			else {
				throw new Exception("Template is not of type DataContextTemplate.  Check the DataContext.cst file to make sure it inherits from DataContextTemplate");
			}
			
		}
	}
}